package urine;

import java.io.*;

import javax.sound.sampled.*;

public class WavPlay
{	
	private Clip clip;

	/** The constructor to load a .wav file 
	 * @throws LineUnavailableException 
	 * @throws IOException 
	 * @throws UnsupportedAudioFileException */
	public WavPlay (String fileName) throws LineUnavailableException, UnsupportedAudioFileException, IOException
	{
		clip = AudioSystem.getClip();
		File f = new File (fileName);
		AudioInputStream ais = AudioSystem.getAudioInputStream (f);
		clip.open(ais);
	}

	/** Play our sound on the default audio system repeatedly. 
	 * @throws LineUnavailableException 
	 * @throws IOException 
	 * @throws UnsupportedAudioFileException */
	public void play () throws LineUnavailableException, UnsupportedAudioFileException, IOException
	{
		if (clip != null)
		{
			clip.loop(Clip.LOOP_CONTINUOUSLY);
		}
	}
	
	/** Play our sound on the default audio system once. 
	 * @throws LineUnavailableException 
	 * @throws IOException 
	 * @throws UnsupportedAudioFileException */
	public void playonce () throws LineUnavailableException, UnsupportedAudioFileException, IOException
	{
		if (clip != null)
		{
			clip.loop(0);
		}
	}

	/** Free up the resources associated with the player. */
	public void close ()
	{
		clip.close (); 
	}
}